﻿(function () {
    var petList = new WinJS.Binding.List([]);
    var vetList = new WinJS.Binding.List([]);

    var loadPets = function () {
        var petDTOs = Data.getPets();

        var currentCount = petList.dataSource.list.length;
        petList.dataSource.list.splice(0, currentCount);

        for (var i = 0; i < petDTOs.length; i++) {
            petList.push(petDTOs[i]);
        }
    }

    var loadVets = function (){
        var vetDTOs = Data.getVets();

        var currentCount = vetList.dataSource.list.length;
        vetList.dataSource.list.splice(0, currentCount);

        for (var i = 0; i < vetDTOs.length; i++) {
            vetList.push(vetDTOs[i]);
        }
    }

    WinJS.Namespace.define("ViewModels", {
        loadPets: loadPets,
        loadVets: loadVets,
        petList: petList,
        vetList: vetList,
        addPet: function (name, birthdate, spiece, gender, barcode, color, vetsname, vetclinic, vetnumber, vetaddress, vaccineplan) {
            Data.addPet(new Models.CatModel(name, birthdate, spiece, gender, barcode, color, vetsname, vetclinic, vetnumber, vetaddress, vaccineplan))
        },
        addVet: function(clinicName, address, vetName, phone){
            Data.addVet(new Models.VetModel(clinicName, address, vetName, phone))
        }
    });
})();